1592B - Hemose Shopping - CodeForces Solution


constructive algorithms dsu math sortings *1200

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#include <iostream>
#include<unordered_map>
#define x first
#define y second

#define  ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

using namespace std;

typedef  long  long LL ;
typedef  unsigned long  long ULL ;
typedef pair<int,int> PII ;
typedef pair<LL,int> PLI ;
const int N = 2e5+10,M = 1000 * 100000 + 10 ,mod = 1000000007,INF1 = 0x3f3f3f3f;
const LL INF2 = 1e17;


//能否通过交换两个距离大于等于 x 的数,使得数组可以按照非递减的顺序来排序。

int  n,x,a[N],b[N];

bool check()
{
    // x == n/2
    for(int i=n-x+1;i<=x;i ++ )
        if(a[i] != b[i]) return 0;
    return 1;
}
inline void solve() {
    cin>>n>>x;
    for(int i=1;i<= n;i ++ )cin>> a[i],b[i] =a[i];

    if(x *2  <=n)
    {
        cout <<"YES" << endl;return ;
    }

    sort(b+1,b+n+1);
    // 这里  x* 2 >= n  ==== x >= n/2
    if(!check()) cout << "NO" << endl;
    else cout << "YES" <<endl;

}
signed main()
{
	ios
    int T;cin>>T;
    while(T -- )
    {
        solve();

    }


    return 0;
}


Comments

Submit
0 Comments
More Questions

1541A - Pretty Permutations
1632C - Strange Test
673A - Bear and Game
276A - Lunch Rush
1205A - Almost Equal
1020B - Badge
1353A - Most Unstable Array
770A - New Password
1646B - Quality vs Quantity
80A - Panoramix's Prediction
1354B - Ternary String
122B - Lucky Substring
266B - Queue at the School
1490A - Dense Array
1650B - DIV + MOD
1549B - Gregor and the Pawn Game
553A - Kyoya and Colored Balls
1364A - XXXXX
1499B - Binary Removals
1569C - Jury Meeting
108A - Palindromic Times
46A - Ball Game
114A - Cifera
776A - A Serial Killer
25B - Phone numbers
1633C - Kill the Monster
1611A - Make Even
1030B - Vasya and Cornfield
1631A - Min Max Swap
1296B - Food Buying